﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SLBehaviourSystem
{
    [ConditionComponent]
    public class StateComponent : ConditionComponent
    {
        public Dictionary<string, ArgumentContainer<bool>> States = new Dictionary<string, ArgumentContainer<bool>>();

        protected string Key;
        public override BehaviourNodeState Excute()
        {
            return States[Key].Argument ? BehaviourNodeState.Success : BehaviourNodeState.Failure;
        }


        protected override void OnBindNode()
        {
            base.OnBindNode();
            string[] values = node.BehaviourData.GetValues();
            for (int i = 0; i < values.Length; i++)
            {
                if (!States.ContainsKey(values[i]))
                {
                    ArgumentContainer<bool> container = new ArgumentContainer<bool>();
                    container.BindNode((IConditionNode)node);
                    States.Add(values[i], container);
                }
            }

            Key = node.BehaviourData.GetString("Key");
        }

        public override void Reset()
        {
            foreach (var condition in States)
            {
                condition.Value.SetValueWithoutEvent(false);
            }
        }
    }
}
